﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Projecturo.Model;
using Projecturo.ProjecturoClient.Command;
using System.Windows.Input;
using Projecturo.ProjecturoClient.Connection;

namespace Projecturo.ProjecturoClient.ViewModel.Project
{
    public class CategoryViewModel : WorkspaceViewModel
    {
        private Category category;
        private Projecturo.Model.Project project;

        public CategoryViewModel()
        {
            this.category = new Category();
            Category.Name = "New Category";
        }

        public override string DisplayName
        {
            get
            {
                return Category.Name;
            }
            protected set
            {
                base.DisplayName = value;
                OnPropertyChanged("DisplayName");
            }
        }

        private Category Category
        {
            get
            {
                return this.category;
            }
        }

        protected override void Save()
        {
            base.Save();

            Category.CreateDate = DateTime.Now;
            Category.Project = this.project;
            Connector.Connectivity.Storage.Save(Category);
        }

        public string Name
        {
            get { return Category.Name; }
            set
            {
                if (Category.Name == value)
                    return;

                Category.Name = value;
                OnPropertyChanged("Name");
            }
        }

        public string Description
        {
            get { return Category.Description; }
            set
            {
                if (Category.Description == value)
                    return;

                Category.Description = value;
                OnPropertyChanged("Description");
            }
        }

        public override void SetParent(object parent)
        {
            this.project = parent as Projecturo.Model.Project;
        }

    }
}
